package top.yfq.multidatasource.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yfq.multidatasource.domain.UserPO;
import top.yfq.multidatasource.service.IUserService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yfq
 * @date 2025/9/26 23:08
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private IUserService userService;

    @GetMapping("/users")
    public List<String> getUsers() {
        List<UserPO> users = userService.list();
        return users.stream().map(UserPO::getUsername).collect(Collectors.toList());
    }

    @GetMapping("/queryById/{id}")
    public UserPO getUsers(@PathVariable("id") long id) {
        return userService.queryById(id);
    }
}
